﻿//======================================================================
//
//        Copyright (C) 苏州逸仙软件    
//        All rights reserved
//
//        filename :D_T_Billboard_Exp.cs
//        description : 广告位信息管理
//
//        created by 邹兴武 at  2010-12-31
//
//======================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace huaguwang
{
    public class D_T_Billboard_Exp : D_T_Billboard
    {
        /// <summary>
        /// 查找分页数据
        /// </summary>
        /// <param name="begin">起始记录数</param>
        /// <param name="pagesize">页大小</param>
        /// <param name="title">搜索关键字:标题</param>
        /// <param name="catetitle">搜索关键字:类别名称</param>
        /// <param name="count">总记录数</param>
        /// <returns>查询结果数据</returns>
        public List<huaguwang.M_T_BillBoard_Exp.clsFind> GetList(int begin, int pagesize, string title, string mtitle, out int count)
        {
            var tab = " T_Billboard ";
            var con = " Flag = 1 ";
            if (!string.IsNullOrEmpty(title))
            {
                con += " and Title like '%'+@title+'%' ";
            }
            if (!string.IsNullOrEmpty(mtitle))
            {
                con += " and Module like '%'+@mtitle+'%' ";
            }

            SqlParameter[] parms = { 
                                   new SqlParameter("@title",SqlDbType.NVarChar,50),
                                   new SqlParameter("@mtitle",SqlDbType.NVarChar,50)
                                   };
            parms[0].Value = title.Exp_Trim();
            parms[1].Value = mtitle.Exp_Trim();

            var countSql = ExpandMSSQL.GetPageSQL(tab, con);
            count = MSSQLHelper.SQLConType.C1.Exp_GetSingle(
                countSql,
                parms
                ).Exp_IntTryParse();

            string strSQL = ExpandMSSQL.GetPageSQL(
                   begin,
                   pagesize,
                   "id,Title,Module,Plate,Position,Rules,Price,State",
                   tab,
                   "id",
                  con,
                   "id desc"
                   );

            var List = MSSQLHelper.SQLConType.C1.Exp_GetList(
                strSQL,
                DR => new huaguwang.M_T_BillBoard_Exp.clsFind()
                {
                    id = DR["id"].Exp_IntTryParse(),
                    Title = DR["Title"].Exp_Trim(),
                    Module = DR["Module"].Exp_Trim(),
                    Plate = DR["Plate"].Exp_Trim(),
                    Position = DR["Position"].Exp_Trim(),
                    Rule = DR["Rules"].Exp_Trim(),
                    Price = ((int)DR["Price"].Exp_DecimalTryParse()).Exp_Trim(),
                    State = DR["State"].Exp_BoolTryParse()?"空闲":"占用"
                },
                parms
                );
            return List;
        }

        public List<huaguwang.M_T_BillBoard_Exp.clsFind> GetAllList()
        {
            var strSql = "select id,Title,Module,Plate,Position,Rules from T_Billboard where Flag = 1 ";
            var List = MSSQLHelper.SQLConType.C1.Exp_GetList(
               strSql,
               DR => new huaguwang.M_T_BillBoard_Exp.clsFind()
               {
                   id = DR["id"].Exp_IntTryParse(),
                   Title = DR["Title"].Exp_Trim(),
                   Module = DR["Module"].Exp_Trim(),
                   Plate = DR["Plate"].Exp_Trim(),
                   Position = DR["Position"].Exp_Trim(),
                   Rule = DR["Rules"].Exp_Trim()
               });
            return List;
        }
    }
}
